﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UIT.ScrumTool.DTO;
using UIT.ScrumTool.Service.Interface;
using UIT.ScrumTool.Service.Model;

namespace UIT.ScrumTool.Service.Business
{

    public partial class ControlService : ITaskService
    {
     public  List<TaskDto> TaskGetByAll()
       {
         List<TaskDto> listTaskDto=new List<TaskDto>();
         List<Task> listTask = dataContext.sp_Task_GetByAll().ToList();
         foreach (var task in listTask)
         {
             TaskDto taskDto=new TaskDto();
             taskDto.Id = task.Id;
             taskDto.Subject = task.Subject;
             taskDto.Description = task.Description;
             taskDto.EstmatedStoryPoint =  Convert.ToSingle(task.EstimatedStoryPoints);
             taskDto.Importance = Convert.ToInt16(task.Importance);
             taskDto.State = Convert.ToInt16( task.State);
             taskDto.TaskBacklog = task.TaskBacklog;
             taskDto.OperatorId = Convert.ToInt16(task.OperatorId);
             taskDto.SprintId = Convert.ToInt16(task.SprintId);
             taskDto.ParentTaskId = Convert.ToInt16(task.ParentTaskId);
             taskDto.ProjectId = Convert.ToInt16(task.ProjectId);
             taskDto.EstimatedDuration = Convert.ToSingle(task.EstimatedDuration);
             listTaskDto.Add(taskDto);

         }
         return listTaskDto;
       }
       public bool TaskInsert(TaskDto taskDto)
       {
           return false;
       }
        public  List<TaskDto> TaskGetByParentId(int parentId)
        {
            try
            {
                List<TaskDto> listTaskDto = new List<TaskDto>();
                List<Task> listTask = dataContext.sp_Task_GetByParentTaskId(parentId).ToList();
                foreach (var task in listTask)
                {
                    TaskDto taskDto = new TaskDto();
                    taskDto.Id = task.Id;
                    taskDto.Subject = task.Subject;
                    taskDto.Description = task.Description;
                    taskDto.EstmatedStoryPoint = Convert.ToSingle(task.EstimatedStoryPoints);
                    taskDto.Importance = Convert.ToInt16(task.Importance);
                    taskDto.State = Convert.ToInt16(task.State);
                    taskDto.TaskBacklog = task.TaskBacklog;
                    taskDto.OperatorId = Convert.ToInt16(task.OperatorId);
                    taskDto.SprintId = Convert.ToInt16(task.SprintId);
                    taskDto.ParentTaskId = Convert.ToInt16(task.ParentTaskId);
                    taskDto.ProjectId = Convert.ToInt16(task.ProjectId);
                    taskDto.EstimatedDuration = Convert.ToSingle(task.EstimatedDuration);
                    listTaskDto.Add(taskDto);
                }
                return listTaskDto;
            }
            catch (Exception)
            {

                return null;
            }
        }
    }
}
